<template>
	<view class="content">
		<u-navbar leftIconColor="#000" :autoBack="true" :placeholder="true" bgColor="rgba(255,255,255,0.0)">
			<view slot="center" class="nav-title">
				收货地址
			</view>
		</u-navbar>
		<view v-if="list.length > 0">
			<view class="order-info" v-for="(item,index) in list" :key="index">
				<view class="order-left">
					<view class="address">
						<view>
							{{item.address_detail}}{{item.address_all}}
						</view>
					</view>
					<view class="order-head">
						<view class="name">
							{{item.name}}
						</view>
						<view class="tell">
							{{item.tel}}
						</view>
						<view v-if="item.status == 1" class="tisp">默认</view>
					</view>
				</view>
				<view style="display: flex;align-items: center;">
					<u-icon name="edit-pen" style="margin-left: 20rpx;" color="#999" size="24" @click="goEdit(2,item)"></u-icon>
					<u-icon name="trash" style="margin-left: 20rpx;" color="#999" size="24" @click="godet(item.id)"></u-icon>
				</view>
			</view>
		</view>
		<view v-else>
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" :marginTop="100" text="地址列表为空">
			</u-empty>
		</view>
		<view class="btn">
			<u-button @click="goEdit(1)" class="btn-color" shape="circle"
				color="#000000" type="primary" text="新增"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: []
			}
		},
		onShow() {
			this.getaddlist()
		},
		methods: {
			godet(id) {
				let app = this
				uni.showModal({
					title: '提示',
					content: '是否删除此地址!',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								mask: true
							})
							let params = {
								id: id
							}
							app.$Request({
								method: 'POST',
								url: '/api/shop/addressDelete',
								data: params
							}).then(res => {
								uni.hideLoading()
								if (res.code == 1) {
									uni.showToast({
										title: '删除成功！',
										icon: 'none'
									})
									app.getaddlist()
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			getaddlist() {
				let params = {

				}
				this.$Request({
					method: 'POST',
					url: '/api/shop/addresslist',
					data: params
				}).then(res => {
					if (res.code == 1) {
						this.list = res.data
					}
				})
			},
			goEdit(num,item) {
				if(num == 1){
					uni.navigateTo({
						url: '/pages/shop/address/edit?num=' + num
					})
				}else{
					uni.navigateTo({
						url: '/pages/shop/address/edit?num=' + num + '&item='+ encodeURIComponent(JSON.stringify(item))
					})
				}
				
			}
		}
	}
</script>
<style>
	page {
		background-color: #f8f8f8;
	}

	.btn-color {
		color: #ffffff !important;
		font-weight: bold;
	}
</style>
<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		padding: 20rpx 30rpx;
		background-image: url('../../../static/home/home-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 500rpx;
		.order-info {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;
			position: relative;
			background: linear-gradient(180deg, rgba(255, 255, 255, 0.7) 7.45%, #FFFFFF 58.5%);
			border: 1px solid #FFFFFF;
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			.icon {
				position: absolute;
				right: 0;
				top: 0;
			}

			.order-left {
				color: #000000;
				font-size: 28rpx;
				font-weight: bold;

				.order-head {
					display: flex;
					align-items: center;
					margin-top: 20rpx;
					.tisp{
						margin-left: 10rpx;
						font-size: 24rpx;
						padding: 5rpx 10rpx;
						background-color: rgba(255, 102, 104, 0.3);
						text-align: center;
						border-radius: 10rpx;
						color: rgba(255, 102, 104, 1);
					}
					.name {
						margin-left: 10rpx;
					}

					.tell {
						margin-left: 20rpx;
					}

					image {
						width: 30.86rpx;
						height: 32rpx;
						margin-left: 20rpx;
					}
				}

				.address {
					color: #999;
					font-size: 24rpx;
				}
			}


		}

		.btn {
			padding: 30rpx;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 30rpx;
		}
	}
</style>